package stu.day19_day24.day21;

import java.util.Arrays;

public class LeetCode875 {
    public int minEatingSpeed(int[] piles, int h) {
        //Arrays.sort(piles);
        int left = 1;
        int right = Arrays.stream(piles).max().getAsInt();
        int mid;
        int sum;
        while (left<right){
            mid = (left+right)/2;
            int finalMid = mid;
            sum = Arrays.stream(piles).map(x->(x+ finalMid -1)/ finalMid).sum();

            if(sum<=h){
                right = mid;
            }else {
                left = mid+1;
            }


        }



        return left;

    }
}
